using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataAccess;
using Entity; 
namespace Business
{
    public class bEquipment
    {
        public static int insertEquipment(eEquipment equip)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@EquipmentName", SqlDbType.NVarChar);
            pr.Value = equip.EquipmentName;
            paramList.Add(pr);

            pr = new SqlParameter("@EquipmentAmount", SqlDbType.Int);
            pr.Value = equip.EquipmentAmount;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("insertEquipment", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }
        public static int updateEquipment(eEquipment equip)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();

            SqlParameter pr = new SqlParameter("@EquipmentID", SqlDbType.Int);
            pr.Value = equip.EquipmentID;
            paramList.Add(pr);

            pr = new SqlParameter("@EquipmentName", SqlDbType.NVarChar);
            pr.Value = equip.EquipmentName;
            paramList.Add(pr);

            pr = new SqlParameter("@EquipmentAmount", SqlDbType.Int);
            pr.Value = equip.EquipmentAmount;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("updateEquipment", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static int deleteEquipment(int equipmentID)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@EquipmentID", SqlDbType.Int);
            pr.Value = equipmentID;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("deleteEquipment", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static DataTable getAllEquipment()
        {
            DBHelper dbh = new DBHelper();
            DataTable dt = dbh.ExecuteQueryDataTable("getAllEquipment", CommandType.StoredProcedure, new List<SqlParameter>());
            dbh.CloseConnection();
            return dt;
        }

        public static eEquipment getEquipmentByID(int equipmentID)
        {
            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@EquipmentID", SqlDbType.Int);
            pr.Value = equipmentID;
            paramList.Add(pr);

            IList il = bBase.LoadQueryString(typeof(eEquipment), "getEquipmentByID", CommandType.StoredProcedure, paramList);
            if (il.Count > 0)
            {
                return (eEquipment)il[0];
            }
            else
            {
                return null;
            }
        }
    }
}
